FROM centos
MAINTAINER mingtielin@outlook.com
ENV Redis_Version 5.0.5
ENV Consul_Version 1.6.1
ENV Build_Tools gcc automake autoconf libtool make
ENV SSH_Tools passwd openssl openssh-server
COPY consul /usr/local/
COPY 6379.conf /usr/local/
COPY init.sh /usr/local/bin/
COPY redis-${Redis_Version}.tar.gz /usr/local/

# 配置镜像支持SSH
RUN yum install -y ${SSH_Tools} \
&& ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' \
&& ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N '' \
# 设置root的密码
&& /bin/echo 'forever' | passwd --stdin root \
&& sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config \
&& sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config \
# 复制consul文件到镜像中
&& mkdir -p /usr/local/consul-${Consul_Version} \
&& mv /usr/local/consul /usr/local/consul-${Consul_Version}/ \
# 安装Redis
&& yum install -y ${Build_Tools} \
&& cd /usr/local/ \
&& tar xzf redis-${Redis_Version}.tar.gz \
&& cd /usr/local/redis-${Redis_Version} \
&& make \
&& mv /usr/local/6379.conf /usr/local/redis-${Redis_Version}/ \
# 清空无用的yum包
&& yum remove -y ${Build_Tools} \
&& yum clean all \
&& rm -rf /usr/local/redis-${Redis_Version}.tar.gz \
&& rm -rf /var/cache/yum/* \
&& chmod 777 /usr/local/bin/init.sh

CMD ["/bin/bash", "/usr/local/bin/init.sh"]